<template>
  <el-button @click="beginAdd()" type="danger" style="margin-top: 10px;">+新增</el-button>
  <el-button @click="save()" type="danger" style="margin-top: 10px;">保存</el-button>
  <el-button @click="cancel()" type="danger" style="margin-top: 10px;">撤销</el-button>
  <el-button @click="delBegin()" type="danger" style="margin-top: 10px;">删除</el-button>
  <hr style="margin-top: 10px;">
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 30px">
          测定日期：<el-date-picker
        v-model="form.phaseDeterDate"
        type="date"
        placeholder="Pick a date"
        :default-value="new Date()"
        style="width: 200px;"
      />
        </el-col>
        <el-col :span="8" style="margin-left: 14px" >
          羊只耳号：       
        <el-select  placeholder="请选择羊只耳号" v-model="form.earNumber" style="width: 200px">
          <el-option v-for="item in EarData" :label="item.earNumber" :value="item.earNumber" />
        </el-select>
      
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 30px">
          牙齿咬合：
        <el-select  placeholder="请选择牙齿咬合" v-model="form.tooth" style="width: 200px;margin-left: -3px">
          <el-option label="正常" value="正常" />
          <el-option label="错齿" value="错齿" />
        </el-select>
        </el-col>
        <el-col :span="8" style="margin-left: 44px">
          毛发：
        <el-select  placeholder="请选择毛发" v-model="form.hair" style="width: 200px;margin-left: -3px">
          <el-option label="1分" value="1分" />
          <el-option label="2分" value="2分" />
          <el-option label="3分" value="3分" />
        </el-select>
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 59px">
          色斑：
        <el-select  placeholder="请选择色斑" v-model="form.darkSpot" style="width: 200px;margin-left: -3px">
          <el-option label="1分" value="1分" />
          <el-option label="2分" value="2分" />
          <el-option label="3分" value="3分" />
        </el-select>
        </el-col>
        <el-col :span="8" style="margin-left: -2px;">
          蹄颜色：
        <el-select  placeholder="请选择蹄颜色" v-model="form.footColor" style="width: 200px">
          <el-option label="1分" value="1分" />
          <el-option label="2分" value="2分" />
          <el-option label="3分" value="3分" />
        </el-select>
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 43px">
          嘴颜色：
        <el-select  placeholder="请选择嘴颜色" v-model="form.mouthColor" style="width: 200px;margin-left: -3px">
          <el-option label="1分" value="1分" />
          <el-option label="2分" value="2分" />
          <el-option label="3分" value="3分" />
        </el-select>
        </el-col>
        <el-col :span="8" style="margin-left: 47px;">
          角：
        <el-select  placeholder="请选择角" v-model="form.horn" style="width: 200px;margin-left: -3px">
          <el-option label="有角" value="有角" />
          <el-option label="无角" value="无角" />
        </el-select>
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 28px;">
          脂肪分布：
        <el-select  placeholder="请选择脂肪分布" v-model="form.fat" style="width: 200px;margin-left: -3px">
          <el-option label="1分" value="1分" />
          <el-option label="2分" value="2分" />
          <el-option label="3分" value="3分" />
        </el-select>
        </el-col>
        <el-col :span="8" style="margin-left: 16px">
          
        </el-col>
    </el-row>

</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
import { ElTable } from 'element-plus';
import { ElMessage, ElMessageBox } from 'element-plus';
const router = useRouter();
const route = useRoute();

const form=reactive({
  earNumber:'',
  phaseDeterDate:new Date(),
  tooth:'',
  hair:'',
  darkSpot:'',
  footColor:'',
  mouthColor:'',
  horn:'',
  fat:'',
  createId:localStorage.getItem('aaa')
})

//羊只耳号下拉框
const EarData:any=ref([])
const getEarData=()=>{
  axios.get('http://localhost:5039/api/SleepBegin/SelectEar').then(res=>{
    console.log(res)
    EarData.value=res.data.item
  })
}

//添加
const save=()=>{
  axios.post('http://localhost:5039/api/SleepWeight/AddPhase',form).then(res=>{
     console.log(res)
     if(res.data.code>0){
      ElMessage.success('添加成功')
    
     }else if(res.data.code==-1){
      ElMessage.error('该耳号的信息已经添加')
     }
  })
}
//撤销
const cancel=()=>{
  form.earNumber='',
  form.tooth='',
  form.hair='',
  form.darkSpot='',
  form.footColor='',
  form.mouthColor='',
  form.horn='',
  form.fat=''
}
//新增
const beginAdd=()=>{
  axios.post('http://localhost:5039/api/SleepWeight/AddPhase',form).then(res=>{
     console.log(res)
     if(res.data.code>0){
      ElMessage.success('添加成功')
      cancel()
     }
  })
}


onMounted(()=>{
  getEarData()
})
</script>